<include file="public@header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li ><a href="{:url('Luckrate/index',array('giftid'=>$giftid))}">幸运礼物中奖设置列表</a></li>
			<li class="active"><a >{:lang('ADD')}幸运礼物中奖设置</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form margin-top-20">

            <div class="form-group">
				<label for="input-name" class="col-sm-2 control-label"><span class="form-required">*</span>数量</label>
				<div class="col-md-6 col-sm-10">
					<volist name="numslist" id="vo">
						<input type="checkbox" name="nums" data-name="{$vo}" value="{$vo}" checked="checked"> {$vo}&nbsp;&nbsp;
					</volist>
					<!-- <select class="form-control" name="nums">
                        <volist name="numslist" id="v">
                        <option value="{$v}">{$v}</option>
                        </volist>
                    </select> -->
				</div>
			</div>
            
            <div class="form-group">
				<label for="input-times" class="col-sm-2 control-label"><span class="form-required">*</span>倍数</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-times" name="times" value="0">
				</div>
			</div>
            
            <div class="form-group">
				<label for="input-name" class="col-sm-2 control-label"><span class="form-required">*</span>是否全站</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" id="isall" name="isall">
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
				</div>
			</div>
            
            <div class="form-group">
				<label for="input-rate" class="col-sm-2 control-label"><span class="form-required">*</span>中奖概率</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-rate" name="rate">%  最小支持0.001%
				</div>
			</div>
            
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
                    <input type="hidden" name="giftid" id="giftid" value="{$giftid}">
					<button type="submit" id="luckrate_add" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
					<a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
				</div>
			</div>
            
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script src="__STATIC__/js/layer/layer.js"></script>
    <script>
	(function(){
		$("#luckrate_add").on('click',function(){
			var giftid = $("input[name='giftid']").val().trim();
			if(!giftid){
				layer.msg('幸运礼物ID异常，请返回礼物列表重新操作');
				return;
			}
			var nums_arr = [];
			var nums = $("input[name='nums']:checked").each(function(){
				nums_arr.push($(this).val());
			});
			if(nums_arr.length == 0){
				layer.msg('数量不能为空');
				return;
			}
			var times = $("input[name='times']").val().trim();
			if(!times){
				layer.msg('倍数不能为空');
				return;
			}
			if(times <= 0){
				layer.msg('中奖倍数不能小于等于0');
				return;
			}
			var isall = $("#isall").val();
			var rate = $("input[name='rate']").val().trim();
			if(!rate){
				layer.msg('中奖概率不能为空');
				return;
			}
			if(rate < 0.001){
				layer.msg('中奖概率不能小于0.001');
				return;
			}
			for(var key in nums_arr){
				ajaxSubmit({
					giftid:giftid,
					times:times,
					isall:isall,
					rate:rate,
					nums:nums_arr[key]
				});
			}
		});

		function ajaxSubmit(params){
			console.log(params)
			$.ajax({
				type:'post',
				url:'/admin/Luckrate/addPost',
				data:params,
				dataType:'json',
				async:false,
				success:function(data){
					var code=data.code;
					var info=data.info;
					if(code != 0){
						layer.msg(data.msg);
						return;
					}
				},
				error:function(e){
					layer.msg('添加幸运礼物中奖设置失败');
					return;
				}
			});
		}
	})()
	</script>
</body>
</html>